package com.android.lovingpet.adopt.host.hostinfo.view;

import android.os.Bundle;
import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.android.lovingpet.R;
import com.android.lovingpet.adopt.host.hostinfo.HostInfoPresenter;
import com.android.lovingpet.adopt.host.hostinfo.IHostInfoContract;
import com.android.lovingpet.base.BaseFragment;
import com.android.lovingpet.bean.HostFoster;
import com.android.lovingpet.util.MyDatePickDialog;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by ikata on 2018/5/22.
 */

public class BackHomeFragment extends BaseFragment<IHostInfoContract.View, HostInfoPresenter> implements IHostInfoContract.View,View.OnClickListener {

    Unbinder unbinder;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.bt_ok)
    Button btOk;
    private HostFoster hostFoster;
    @Override
    protected int setContentView() {
        return R.layout.fragment_back_home;
    }

    @Override
    protected void onCreateView(View view) {
        EventBus.getDefault().register(this);
        unbinder = ButterKnife.bind(this, view);
    }

    @Override
    public HostInfoPresenter createPresenter() {
        return new HostInfoPresenter();
    }

    @Override
    public IHostInfoContract.View createView() {
        return this;
    }



    @Override
    public void showToast(String msg) {

    }

    @Override
    public void next(@Nullable Bundle bundle) {
        if (bundle==null) {
            getFragmentManager().popBackStack();
            return;
        }
        hostFoster=bundle.getParcelable("hostFoster");

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void getHostFoster(Integer petId)
    {
        Log.d("idid",petId+"-");
        getPresenter().getHostFosterById(petId);
    }

    @OnClick({R.id.bt_ok})
    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.bt_ok:
                getPresenter().updateState(hostFoster.getFosterId(),2);
                break;
        }
    }


}
